package leetCode;

import java.net.InetAddress;
import java.util.List;

public class t203 {
    public static void main(String[] args) {
//        ListNode node=new ListNode(1,new ListNode(2,new ListNode(6,new ListNode(3,new ListNode(4,new ListNode(5,new ListNode(6,null)))))));
        ListNode node=new ListNode(7,new ListNode(7,new ListNode(7,new ListNode(7))));

        new Solution2().removeElements(node,7);

    }
}
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
class Solution2 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyHead=new ListNode(0,head);
        ListNode slow=dummyHead;
        ListNode fast=dummyHead.next;
        while (fast!=null){
            if (fast.val==val){
                slow.next=fast.next;
                fast=slow.next;
            }else {
                slow=fast;
                fast=fast.next;
            }
        }
        return dummyHead.next;
    }
}